<template>
  <div class="home-container">
    <!-- 顶部导航栏 -->
    <el-header class="app-header">
      <div class="logo">
        <img src="@/assets/logo.png" alt="Logo" class="logo-image">
      </div>
    </el-header>

    <!-- 主要内容区域 -->
    <el-main class="main-content">
      <!-- 功能卡片区域 -->
      <el-card class="feature-section" shadow="never">
        <template #header>
          <div class="section-header">
            <el-icon :size="18" color="#4caf50"><Menu /></el-icon>
            <span class="section-title">核心功能</span>
          </div>
        </template>

        <el-card
            v-for="item in mainFeatures"
            :key="item.path"
            shadow="hover"
            class="feature-card"
            @click="navigateTo(item.path)"
        >
          <div class="card-content">
            <el-icon :size="24" :color="item.color" class="card-icon">
              <component :is="item.icon" />
            </el-icon>
            <div class="card-text">
              <h3>{{ item.title }}</h3>
              <p>{{ item.description }}</p>
            </div>
            <el-icon :size="18" class="card-arrow"><ArrowRight /></el-icon>
          </div>
        </el-card>
      </el-card>

      <!-- 快捷入口区域 -->
      <el-card class="quick-access-section" shadow="never">
        <template #header>
          <div class="section-header">
            <el-icon :size="18" color="#4caf50"><Star /></el-icon>
            <span class="section-title">快捷入口 (未来可能增加的功能)</span>
          </div>
        </template>

        <el-row :gutter="12">
          <el-col
              v-for="item in quickAccess"
              :key="item.path"
              :xs="12"
              :sm="6"
              class="quick-access-col"
          >
            <el-card
                shadow="hover"
                class="quick-access-item"
            >
              <div class="quick-access-content">
                <el-icon :size="28" :color="item.color">
                  <component :is="item.icon" />
                </el-icon>
                <span>{{ item.title }}</span>
              </div>
            </el-card>
          </el-col>
        </el-row>
      </el-card>
    </el-main>

    <!-- 底部导航栏 -->
    <el-footer class="bottom-nav">
      <el-menu
          mode="horizontal"
          :default-active="activeIndex"
          class="nav-menu"
          @select="handleMenuSelect"
          active-text-color="#4caf50"
          :ellipsis="false"
      >
        <el-menu-item index="/home">
          <template #title>
            <el-icon :size="24"><HomeFilled /></el-icon>
            <span>首页</span>
          </template>
        </el-menu-item>
        <el-menu-item index="/detection">
          <template #title>
            <el-icon :size="24"><Camera /></el-icon>
            <span>识别</span>
          </template>
        </el-menu-item>
        <el-menu-item index="/gallery">
          <template #title>
            <el-icon :size="24"><Notebook /></el-icon>
            <span>图鉴</span>
          </template>
        </el-menu-item>
      </el-menu>
    </el-footer>
  </div>
</template>

<script setup>
import { ref, computed } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import {
  Menu, ArrowRight, Star,
  HomeFilled, Camera, Notebook,
  Clock, ChatDotRound, Sunny, ShoppingCart, Connection
} from '@element-plus/icons-vue'

const router = useRouter()
const route = useRoute()

const activeIndex = computed(() => route.path)

const mainFeatures = ref([
  {
    icon: Camera,
    title: '植物状态监测',
    description: '监测植物生长状态和健康状况',
    path: '/detection',
    color: '#4caf50'
  },
  {
    icon: Notebook,
    title: '作物图鉴',
    description: '查看各类作物详细信息',
    path: '/gallery',
    color: '#8bc34a'
  },
  {
    icon: Clock,
    title: '历史记录',
    description: '查看您的识别记录',
    path: '/history',
    color: '#cddc39'
  }
])

const quickAccess = ref([
  {
    icon: ChatDotRound,
    title: '专家建议',
    path: '/advice',
    color: '#4caf50'
  },
  {
    icon: Sunny,
    title: '天气信息',
    path: '/weather',
    color: '#2196f3'
  },
  {
    icon: ShoppingCart,
    title: '市场价格',
    path: '/market',
    color: '#ff9800'
  },
  {
    icon: Connection,
    title: '农友社区',
    path: '/community',
    color: '#9c27b0'
  }
])

const navigateTo = (path) => {
  router.push(path)
}

const handleMenuSelect = (index) => {
  router.push(index)
}
</script>

<style scoped>
.home-container {
  height: 100vh;
  display: flex;
  flex-direction: column;
  background-color: #f8faf8;
  font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;
  position: relative;
  overflow: hidden;
}

/* 顶部导航栏 */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 15px;
  height: 60px;
  background-color: white;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

.logo-image {
  height: 40px;
  border-radius: 40px;
}

/* 主要内容区域 */
.main-content {
  flex: 1;
  padding: 15px 15px 70px;
  overflow-y: auto;
}

/* 分区标题 */
.section-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title {
  font-size: 16px;
  font-weight: bold;
  color: #333;
}

/* 功能卡片 */
.feature-section {
  margin-bottom: 20px;
  border-radius: 12px;
}

.feature-card {
  margin-bottom: 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s;
}

.feature-card:last-child {
  margin-bottom: 0;
}

.feature-card:hover {
  transform: translateY(-3px);
}

.card-content {
  display: flex;
  align-items: center;
  padding: 10px 0;
}

.card-icon {
  margin-right: 15px;
  flex-shrink: 0;
}

.card-text {
  flex: 1;
}

.card-text h3 {
  font-size: 16px;
  color: #333;
  margin: 0 0 5px 0;
}

.card-text p {
  font-size: 12px;
  color: #888;
  margin: 0;
}

.card-arrow {
  color: #ccc;
  margin-left: 10px;
}

/* 快捷入口区域 */
.quick-access-section {
  border-radius: 12px;
  margin-bottom: 20px;
}

.quick-access-col {
  margin-bottom: 12px;
}

.quick-access-item {
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s;
  height: 100%;
  margin: 0;
}

.quick-access-item:hover {
  transform: translateY(-3px);
}

.quick-access-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 15px 5px;
  gap: 10px;
}

.quick-access-content span {
  font-size: 14px;
  color: #555;
}

/* 底部导航栏 */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 0;
  height: 64px;
  background-color: white;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
  z-index: 1000;
}

.nav-menu {
  display: flex;
  justify-content: space-around;
  border: none;
  height: 100%;
}

.nav-menu :deep(.el-menu-item) {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: 64px;
  padding: 0;
  border-bottom: none;
  transition: all 0.3s;
}

.nav-menu :deep(.el-menu-item.is-active) {
  color: #4caf50 !important;
  background-color: #e8f5e9 !important;
}

.nav-menu :deep(.el-menu-item .el-icon) {
  margin-right: 0;
  margin-bottom: 6px;
  font-size: 20px;
}
/* 响应式调整 */
@media (max-width: 480px) {
  .main-content {
    padding: 10px 10px 70px;
  }

  .feature-card {
    margin-bottom: 10px;
  }

  .quick-access-item {
    padding: 12px 5px;
  }
}
</style>